import java.io.Console;
import java.util.ArrayList;
import java.util.Scanner;

public class MyRunSonTwo implements Runnable {
	ArrayList<String> lista = new ArrayList<String>();

	Monitor monitor2;

	public MyRunSonTwo(Monitor monitor) {
		this.monitor2 = monitor;
	}

	@Override
	public void run() {
		pedirCadena(lista);
	}

	public void pedirCadena(ArrayList<String> listaCadenas) {
		synchronized (Scanner.class) {
			System.out.println("ingrese cualquier tecla para comenzar / fin para salir");
			String aux = "";
			while (!aux.equalsIgnoreCase("fin")) {
				Scanner sc = new Scanner(System.in);
				aux = sc.next();
				if (this.monitor2.isDosThreadVivos()
						&& !aux.equalsIgnoreCase("fin")) {
					listaCadenas.add(aux);
					Scanner.class.notify();
					try {
						Scanner.class.wait();
					} catch (InterruptedException e) {
					}
				} else if (aux.equalsIgnoreCase("fin")) {
					monitor2.setDosThreadVivos(false);
					Scanner.class.notify();
				}
			}

		}
	}
}
